package com.rem.concurrency.multithreading.state;

/**
 * 线程优先级
 * 最大10 最小1   数字越大权重越大  不代表一定就是靠前
 *
 * @author Rem
 * @date 2021-03-04
 */

public class ThreadPrioority {

    public static void main(String[] args) {
        System.err.println(Thread.currentThread().getName() + "-----" + Thread.currentThread().getPriority());
        TestP testP = new TestP();

        Thread thread = new Thread(testP);
        Thread thread2 = new Thread(testP);
        Thread thread3 = new Thread(testP);
        Thread thread4 = new Thread(testP);
        Thread thread5 = new Thread(testP);
        Thread thread6 = new Thread(testP);


        thread.setPriority(1);
        thread.start();
        thread2.setPriority(Thread.MAX_PRIORITY);
        thread2.start();
        thread3.setPriority(Thread.MIN_PRIORITY);
        thread3.start();
        thread4.setPriority(4);
        thread4.start();

        //报错 最大10 最小1
        // thread5.setPriority(11);
        // thread6.setPriority(-1);
        thread5.setPriority(7);
        thread5.start();
        thread6.setPriority(2);
        thread6.start();
    }


}

class TestP implements Runnable {
    @Override
    public void run() {
        System.err.println(Thread.currentThread().getName() + "-----" + Thread.currentThread().getPriority());
    }
}
